package org.hawkular.datamining.forecast.utils;

import org.joda.time.*;

/**
 * @Author: jrxian
 * @Date: 2018/12/26 10:24
 */
public enum JodaTimeUnit {
	MILLISECONDS {
		public long convert(long millis) {
			return millis;
		}
	},
	SECONDS {
		public long convert(long millis) {
			return millis / DateTimeConstants.MILLIS_PER_SECOND;
		}
	},
	MINUTES {
		public long convert(long millis) {
			return millis / DateTimeConstants.MILLIS_PER_MINUTE;
		}
	},
	HOURS {
		public long convert(long millis) {
			return millis / DateTimeConstants.MILLIS_PER_HOUR;
		}
	},
	DAYS {
		public long convert(long millis) {
			return millis / DateTimeConstants.MILLIS_PER_DAY;
		}
	};

	public long convert(ReadableDuration duration) {
		return convert(duration.getMillis());
	}

	public long convert(ReadableInterval interval) {
		return convert(interval.toDuration());
	}

	public long convert(ReadablePeriod period) {
		Period period0 = period.toPeriod();
		return convert(period0.toStandardDuration());
	}

	public long convert(LocalDate date) {
		return convert(date.toDateTime(LocalTime.MIDNIGHT, DateTimeZone.UTC));
	}

	public long convert(LocalTime time) {
		return convert(time.getMillisOfDay());
	}

	public long convert(DateTime occur) {
		return convert(occur.getMillis());
	}

	public abstract long convert(long millis);
}
